const Router = require('koa-router')
const { Posts } = require('../../models/posts')
const { FollowUser } = require('../../models/followUser')
const { Auth } = require('../../core/middleware/auth')
const router = new Router({
  prefix: '/v1/posts',
})
router.get('/details', new Auth(true).m, async (ctx, next) => {
  const { id } = ctx.request.query
  let details = await Posts.getPostsDetila(id, ctx.auth ? ctx.auth.id : '')
  if (ctx.auth) {
    const follow = await FollowUser.getDetails(details.user.id, ctx.auth.id)
    details.dataValues.isFollow = follow ? true : false
  }
  ctx.body = {
    code: 200,
    data: details
  }
})
module.exports = router

